package response;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/goto")
public class GoToServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String type = req.getParameter("type");
        if("1".equals(type)){//重定向
//            resp.setStatus(301);
//            resp.setHeader("Location","hello.html");
            //以上代码可以简化为sendRedirect
            resp.sendRedirect("http://www.sogou.com");
        }else if("2".equals(type)){//转发
            req.getRequestDispatcher("http://www.baidu.com").forward(req,resp);
        }
    }
}
